package com.xxx.ware.ware_manage_sys.controller.goods;

import com.xxx.ware.ware_manage_sys.bean.dto.GoodsQueryDto;
import com.xxx.ware.ware_manage_sys.bean.dto.GoodsSaveUpdateDto;
import com.xxx.ware.ware_manage_sys.bean.dto.WebResultDto;
import com.xxx.ware.ware_manage_sys.bean.vo.GoodsVo;
import com.xxx.ware.ware_manage_sys.bean.vo.ResultVo;
import com.xxx.ware.ware_manage_sys.service.IWmsGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "仓库物品模块")
@RestController
@RequestMapping("/wms/goods")
@MapperScan("com.xxx.ware.ware_manage_sys.mapper")
@Slf4j
public class GoodsController {

    @Autowired
    private IWmsGoodsService wmsGoodsService;

    @PostMapping("/saveGoods")
    @ApiOperation(value = "添加物品", notes = "添加物品", httpMethod = "POST")
    public ResultVo<Boolean> saveGoods(@RequestBody @Validated GoodsSaveUpdateDto goodsSaveUpdateDto){
        try {
            return ResultVo.data(wmsGoodsService.saveGoods(goodsSaveUpdateDto));
        } catch (Exception e) {
            log.error("添加物品失败，失败原因：" + e);
            return ResultVo.fail("添加物品失败");
        }
    }

    @PostMapping("/goodsList")
    @ApiOperation(value = "物品列表", notes = "物品列表", httpMethod = "POST")
    public ResultVo<WebResultDto<GoodsVo>> getGoodsList(@RequestBody GoodsQueryDto goodsQueryDto){
        try {
            return ResultVo.data(wmsGoodsService.getGoodsList(goodsQueryDto));
        } catch (Exception e) {
            log.error("查询物品列表失败，对应失败原因：" + e);
            return ResultVo.fail("查询物品列表失败");
        }
    }

    @PostMapping("/update")
    @ApiOperation(value = "编辑物品", notes = "编辑物品", httpMethod = "POST")
    public ResultVo<Boolean> updateGoods(@RequestBody @Validated GoodsSaveUpdateDto goodsSaveUpdateDto){
        try {
            return ResultVo.data(wmsGoodsService.updateGoods(goodsSaveUpdateDto));
        } catch (Exception e) {
            log.error("编辑物品列表失败，对应失败原因：" + e);
            return ResultVo.fail("编辑物品失败");
        }
    }

}
